//Display list for screen

function DisplayList() {
	this.objectList = new Array();
	
	this.addChild = function(child) {
		this.objectList.push(child);
	
	}
	
	this.removeChild = function(child) {
		var removeIndex = null;
		removeIndex = this.objectList.indexOf(child,0);
		if (removeIndex != null) {
			this.objectList.splice(removeIndex,1);
		}
	}
	
	this.draw = function() {
		for (var i = 0; i < this.objectList.length; i++) {
			tempObject = this.objectList[i];
	  		tempObject.draw();
	  	}
	}
	
	this.onMouseUp = function(event) {
		Debugger.log("mouse clicked in display list");
		var mouseX;
		var mouseY;
			
		if ( event.layerX ||  event.layerX == 0) { // Firefox
			mouseX = event.layerX ;
			mouseY = event.layerY;
		} else if (event.offsetX || event.offsetX == 0) { // Opera
			mouseX = event.offsetX;
			mouseY = event.offsetY;
		}
		
		for (i=0; i< this.objectList.length; i++) {
			var to = this.objectList[i];
			if ( (mouseY >= to.y) && (mouseY <= to.y+to.height) && (mouseX >= to.x) && (mouseX <= to.x+to.width) ) {
				Debugger.log("mouse clickied on this:" + to)
				to.onMouseUp(mouseX,mouseY)
			}
		}
	
	}
}
